package com.gz.rabbitmq.routing;

import com.gz.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer1 {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection("demo");

        Channel channel = connection.createChannel();

        channel.exchangeDeclare(Producer.EX_CHANGE_NAE, BuiltinExchangeType.DIRECT);

        channel.queueDeclare(Producer.ROUTING_QUEUE_1,true,false,false,null);

        channel.queueBind(Producer.ROUTING_QUEUE_1,Producer.EX_CHANGE_NAE,"insert");

        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println(new String(body,"UTF-8"));
            }
        };

       channel.basicConsume(Producer.ROUTING_QUEUE_1,true,consumer);
    }
}
